package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmMaterialDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmMaterialService;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author mcm
 * @since 2022-01-15
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(tags = "自媒体图文素材信息表接口")
@CrossOrigin
public class WmMaterialController {

    @Autowired
    private IWmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile file) {
        return wmMaterialService.upload(file);
    }

    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto) {
        return wmMaterialService.listByCollection(dto);
    }

    @PutMapping("/collect/{id}")
    public ResponseResult getCollection(@PathVariable("id") Integer id) {

        return wmMaterialService.getCollection(id,1);
    }

    @PutMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollection(@PathVariable("id") Integer id) {

        return wmMaterialService.getCollection(id,0);
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteMaterial(@PathVariable("id") Integer id) {

        return wmMaterialService.deleteMaterial(id);
    }
}
